package fun.werfamily.wf.auth.core.service;

import fun.werfamily.wf.auth.core.dto.LoginUserDTO;
import fun.werfamily.wf.auth.core.feign.client.UserCoreClient;
import fun.werfamily.wf.auth.core.feign.dto.UserInfoDTO;
import jakarta.annotation.Resource;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: Mr.WenMing Zhang
 * @Date: 2023-04-03 22:35
 * @Description:
 */
@Service
public class UserDetailServiceImpl implements UserDetailsService {
    @Resource
    private UserCoreClient userCoreClient;


    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        UserInfoDTO userInfo = userCoreClient.getUserInfo(username);
        return new LoginUserDTO(userInfo);
    }
}
